package cn.lg.soar.common.util.current;

import java.util.function.Supplier;

/**
 * 当前用户处理器
 * @author luguoxiang
 * @date 2022/4/3
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
public class ThreadLocalHolder {

    /**
     * 清除当前用户信息（请求处理完成）
     */
    public static void removeCurrentUser() {
        UserContext.remove();
    }

    /**
     * 设置当前用户（请求处理器前）
     * @param currentUser
     */
    public static void setCurrentUser(ICurrentUser currentUser) {
        UserContext.set(currentUser);
    }

    /**
     * 配置加载器实现懒加载
     * @param loader
     */
    public static void setCurrentUserLoader(Supplier<ICurrentUser> loader){
        UserContext.setLoader(loader);
    }

    public static void setCurrentUserThreadLocal(ThreadLocal<ICurrentUser> threadLocal) {
        UserContext.CURRENT_USER_THREAD_LOCAL = threadLocal;
    }

    public static void setResourceThreadLocal(ThreadLocal<String> threadLocal) {
        CurrentThreadContext.RESOURCE_THREAD_LOCAL = threadLocal;
    }
}
